
public class InToPost {
    private Stackss myStack;
    private String input;
    private String outPut="";
    //constructor
    public InToPost(String input){
        this.input = input;
        myStack = new Stackss(this.input.length());
    }
    //do translation to postFix
    public  String doTrans(){
        for(int i=0; i<input.length(); i++){
            char ch = input.charAt(i);
            switch(ch){
                case '+':
                case '-':
                    this.getOper(ch,1);
                    break;
                case '*':
                case '/':
                    this.getOper(ch,2);
                    break;
                case '(':
                    this.getOper(ch, 3);
                    break;
                case ')':
                    this.getOper(ch, 4);
                    break;
                default:
                    this.outPut = this.outPut +' '+ ch + ' ';
            }
        }
        while(!this.myStack.isEmpty()){
            this.outPut = this.outPut + this.myStack.pop()+' ';
        }
        return this.outPut;
    }
    //get operator from input
    public void getOper(char ch, int prect1){
        char temp;
        if(this.myStack.isEmpty()||prect1==3){
            this.myStack.push(ch);
        }
        else if(prect1==4){
            while(!this.myStack.isEmpty()){
                temp = this.myStack.pop();
                if(temp=='(')continue;
                this.outPut = this.outPut + temp+' ';
            }
        }
        else if(prect1==1){
            temp = this.myStack.peek();
            if(temp=='(') this.myStack.push(ch);
            else{
                this.outPut = this.outPut + this.myStack.pop()+' ';
                this.myStack.push(ch);
            }
        }
        else{
            temp = this.myStack.peek();
            if(temp=='('||temp=='+'||temp=='-') this.myStack.push(ch);
            else{
                this.outPut = this.outPut + this.myStack.pop()+' ';
            }
        }
    }
}